<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of account
 *
 * @author lz06
 */
class AdminDb {

    private $dbc;

    function __construct(DBC $dbc) {
        $this->dbc = $dbc;
    }

    /**
     * 根据用户名，密码获得用户信息
     * @param DBC $dbc
     * @param type $accountId
     * @param type $accountPass
     * @return type
     */
    public function getAccount($accountId, $accountPass) {
        $sql = "SELECT * FROM Admin WHERE Admin = '" . $accountId . "' AND Password = '" . $accountPass . "'";
        $data = $this->dbc->fetchData($sql);
        for ($i = 0; $i < count($data); $i++) {
            unset($data[$i]['Password']);
        }
        return $data;
    }

    /**
     * 用户更新密码
     * @param type $accUnique
     * @param type $accountId
     * @param type $oldPassword
     * @param type $newPassword
     * @return type
     */
    public function modifyPassword($accUnique, $accountId, $oldPassword, $newPassword) {
        $sql = "UPDATE Admin SET Admin = '" . $newPassword . "' WHERE id_x = '" . $accUnique . "' AND Admin = '" . $accountId . "' AND Password = '" . $oldPassword . "'";
        return $this->dbc->execute($sql);
    }

}
